home *** CD-ROM | disk | FTP | other *** search
/ L' Effet Pommier 3 / L'Effet Pommier - Volume 03.iso / Graphismes / Bitmap / NIH Image 1.59 / Macros / Corpus Collosum Macros < prev    next >
Text File  |  1993-11-03  |  4KB  |  207 lines

  1. {
  2. This is a set of macros for measuring the area of various regions in the corpus collosum in MRI scans. It assumes that the scans are 256x256, that you are using a 19" monitor, that the Undo buffer is set to 600K, and that you have a lot of RAM.
  3.  
  4. This is the procedure:
  5.  
  6. 1) Open or activate the scan to be analyzed and type Z.
  7. 2) Draw a base line using the line tool.
  8. 3) Draw perpendicular lines by typing S or R.
  9. 4) Draw a perpendicular line at an arbitrary location by clicking
  10.    on the base line with the line tool and typing A.
  11. 5) Outline the corpus collosum.
  12. 6) Threshold by typing B.
  13. 7) Measure the areas by clicking inside each region with the wand.
  14. 8) Revert to grayscale by typing G. (Optional)
  15. 9) Dispose of the 768x768 working window by typing D.
  16. }
  17.  
  18. var  {Global variables}
  19.   WindowNum:integer;
  20.   x1,y1,x2,y2,LineWidth:integer;
  21.   size,angle,dx,dy,pi,theta:real;
  22.   width,height,dx,dy,i:integer;
  23.  
  24.  
  25. macro 'Zoom Window [Z]';
  26. var
  27.   top,left,width,height:integer;
  28. begin
  29.   RequiresVersion(1.50);
  30.   if UndoBufferSize<(768*768) then begin
  31.     PutMessage('Use Preferences(Options Menu) to increase the Undo buffer size to at least 600K.');
  32.     exit;
  33.   end;
  34.   GetPicSize(width,height);
  35.   if width>600 then begin
  36.     PutMessage('Window has already been zoomed.');
  37.     exit;
  38.   end;
  39.   KillRoi;
  40.   SetScale(1,'mm'); {Assume 1 pixel/mm}
  41.   WindowNum:=PicNumber;
  42.   SetScaling('Nearest; New Window');
  43.   ScaleAndRotate(3,3,0);
  44.   ChangeValues(254,255,253); {Reserve 254-255(black) for graphics}
  45.   SetForegroundColor(254);
  46.   ApplyLUT;
  47.   SetLineWidth(1);
  48. end;
  49.  
  50.  
  51. procedure DrawPerpendicularLine(x,y:integer);
  52. begin
  53.   moveto(x,height-y);
  54.   lineto(x+size*cos(theta+angle),height-(y+size*sin(theta+angle)));
  55.   moveto(x,height-y);
  56.   lineto(x+size*cos(theta-angle),height-(y+size*sin(theta-angle)));
  57. end;
  58.  
  59.  
  60. procedure DrawLines(nSegments:integer);
  61. begin
  62.   for i:=1 to nSegments-1 do
  63.     DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  64. end;
  65.  
  66.  
  67. procedure DrawLeftLine;
  68. var
  69.   nSegments,i:integer;
  70. begin
  71.   nSegments:=5;
  72.   i:=1;
  73.   DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  74. end;
  75.  
  76.  
  77. procedure DrawRightLine;
  78. var
  79.   nSegments,i:integer;
  80. begin
  81.   nSegments:=5;
  82.   i:=4;
  83.   DrawPerpendicularLine(x1+round(i*dx/nSegments),y1+round(i*dy/nSegments));
  84. end;
  85.  
  86.  
  87. procedure DrawThePerpendiculars;
  88. begin
  89.   GetLine(x1,y1,x2,y2,LineWidth);
  90.   if (x1<0) or ((x2-x1)<10) then begin
  91.     PutMessage('Select the base line first using the line selection tool.');
  92.     exit;
  93.   end;
  94.   Fill;
  95.   KillRoi;
  96.   size:=sqrt(sqr(x2-x1)+sqr(y2-y1))/2;
  97.   angle:=90; {degrees}
  98.   pi:=3.14159;
  99.   GetPicSize(width,height);
  100.   y1:=height-y1;
  101.   y2:=height-y2;
  102.   angle:=(angle/180)*pi;
  103.   dx:=x1-x2;
  104.   dy:=y1-y2;
  105.   if dx=0 then begin
  106.     if dy>=0 then theta:=pi/2 else theta:=3/2*pi
  107.   end else begin
  108.     theta:=arctan(dy/dx);
  109.     if dx<0 then theta:=theta+pi;
  110.   end;
  111.   dx:=x2-x1;
  112.   dy:=y2-y1;
  113.   SetForegroundColor(255);
  114.   DrawLines(2);
  115.   DrawLines(3);
  116. end;
  117.  
  118.  
  119. Macro 'Draw Perpendicular Lines-Left[S]';
  120. begin
  121.   DrawThePerpendiculars;
  122.   DrawLeftLine;
  123. end;
  124.  
  125.  
  126. Macro 'Draw Perpendicular Lines-Right[R]';
  127. begin
  128.   DrawThePerpendiculars;
  129.   DrawRightLine;
  130. end;
  131.  
  132.  
  133. macro 'Draw Arbitrary Perpendicular Line [A]';
  134. var
  135.   xx1,yy1,xx2,yy2:integer;
  136.   fraction:real;
  137. begin
  138.   if angle=0 then begin
  139.     PutMessage('Draw the other perpendiclular lines first.');
  140.     exit;
  141.   end;
  142.   if dx=0 then begin
  143.     PutMessage('Draw base line first.');
  144.     exit;
  145.   end;
  146.   GetLine(xx1,yy1,xx2,yy2,LineWidth);
  147.   if not ((xx1>x1) and (xx1<x2)) then begin
  148.     PutMessage('Click with the line selection tool first.');
  149.     exit;
  150.   end;
  151.   KillRoi;
  152.   fraction:=(xx1-x1)/dx;
  153.   DrawPerpendicularLine(x1+round(dx*fraction),y1+round(dy*fraction));
  154. end;
  155.  
  156.  
  157. macro 'Make Binary [B]';
  158. var
  159.   top,left,width,height:integer;
  160. begin
  161.   GetRoi(top,left,width,height);
  162.   if width=0 then begin
  163.     PutMessage('Please outline first.');
  164.     exit;
  165.   end;
  166.   DrawBoundary;
  167.   KillRoi;
  168.   SetThreshold(255);
  169.   SetOptions('Area');
  170.   LabelParticles(false);
  171.   IncludeInteriorHoles(true);
  172.   WandAutoMeasure(true);
  173.   ResetCounter;
  174.   ShowResults;
  175. end;
  176.  
  177. macro 'Make Grayscale [G]';
  178. begin
  179.   ResetGrayMap;
  180.   KillRoi;
  181. end;
  182.  
  183. macro 'Dispose of Window [D]';
  184. var
  185.   width,height:integer;
  186. begin
  187.   GetPicSize(width,height);
  188.   if width>600
  189.     then dispose
  190.     else exit;
  191.   if windowNum<>0 then SelectPic(WindowNum);
  192. end;
  193.  
  194. macro 'Adjust Areas [Q]';
  195. var
  196.   i:integer;
  197. begin
  198.   for i:=1 to rCount do
  199.     rArea[i]:=rArea[i]/9;
  200.   ShowResults;
  201. end;
  202.  
  203.  
  204.  
  205.  
  206.  
  207.